<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<div class="bjui-pageHeader" style="background-color:#fefefe; border-bottom:none;">
    <form data-toggle="ajaxsearch"
          data-options="{searchDatagrid:$.CurrentNavtab.find('#loanReturningTable')}">
        <fieldset>
            <legend style="font-weight:normal;">搜索：</legend>

            <div class="bjui-row col-3">
                <label class="row-label">标的名称:</label>
                <div class="row-input">
                    <input type="text" name="fullName" class="form-control" size="30" title="标的名称">
                </div>

                <label class="row-label">标的编号：</label>
                <div class="row-input">
                    <input type="text" name="loanNumber" class="form-control" size="30" title="标的编号">
                </div>

                <label class="row-label">借款人用户名：</label>
                <div class="row-input">
                    <input type="text" name="userName" class="form-control" size="30" title="借款人用户名">
                </div>

                <label class="row-label">发布时间：</label>
                <div class="row-input">
                    <input type="text" name="dateFromTo.from" data-toggle="datepicker" data-nobtn="true" size="14">
                    -
                    <input type="text" name="dateFromTo.to" data-toggle="datepicker" data-nobtn="true" size="14">
                </div>

                <label class="row-label"></label>
                <div class="row-input">
                    <div class="btn-group">
                        <button type="submit" class="btn-green" data-icon="search">搜索</button>
                        <button type="reset" class="btn-orange" data-icon="times">重置</button>
                    </div>
                </div>

            </div>
        </fieldset>
    </form>
</div>
<div class="bjui-pageContent">
    <table id="loanReturningTable" class="table table-bordered">
    </table>
</div>
<script type="text/javascript" src="/js/toolDate.js"></script>
<script type="text/javascript" src="/js/loan/loanDisplay.js"></script>
<script type="text/javascript">
    $(function () {
        var columns = [
            {
                label: '标的名称',
                align: 'center',
                render: function (value, data) {
                    if (data.loan === undefined) {
                        return '';
                    }
                    return data.loan.fullName;
                }
            },
            {
                label: '标的编号',
                align: 'center',
                render: function (value, data) {
                    if (data.loan === undefined) {
                        return '';
                    }
                    return '<a href="javascript:loanInfo(\'' + data.loan.loanId + '\')">' + data.loan.loanNumber + '</a>';
                }
            },
            {
                label: '借款人名称',
                align: 'center',
                render: function (value, data) {
                    if (data.loan === undefined) {
                        return '';
                    }
                    return '<a href="javascript:userInfo(\'' + data.loan.userId + "','" + data.loan.userName + '\')">' + data.loan.userName + '</a>';
                }
            },
            {
                label: '借款金额',
                align: 'center',
                render: function (value, data) {
                    if (data.loan === undefined) {
                        return '';
                    }
                    var loanAmountD = data.loan.loanAmountD;
                    return loanAmountD + "元";
                },
                total:'returning_loanAmountD'
            },
            {
                label: '已借款金额',
                align: 'center',
                render: function (value, data) {
                    if (data.loan === undefined) {
                        return '';
                    }
                    return data.loan.currentAmountD + "元";
                }
            },
            {
                label: '完成比例',
                align: 'center',
                render: function (value, data) {
                    if (data.loan === undefined) {
                        return '';
                    }
                    return data.loan.currentAmountD / data.loan.loanAmountD * 100 + "%";
                }
            },
            {
                label: '融资期限',
                align: 'center',
                render: function (value, data) {
                    if (data.loan === undefined) {
                        return '';
                    }
                    return data.loan.allottedTime + "天";
                }
            },
            {
                label: '年利率',
                align: 'center',
                render: function (value, data) {
                    if (data.loan === undefined) {
                        return '';
                    }
                    return data.loan.rateD + "%";
                }
            },
            {
                label: '借款期限',
                align: 'center',
                render: function (value, data) {
                    if (data.loan === undefined) {
                        return '';
                    }
                    return data.loan.loanTime + "天";
                }
            },
            {
                label: '状态',
                align: 'center',
                render: function (value, data) {
                    if (data.loan === undefined) {
                        return '';
                    }
                    return data.loan.loanStatusStr;
                }
            },
            {
                label: '创建时间',
                align: 'center',
                render: function (value, data) {
                    if (data.loan === undefined) {
                        return '';
                    }
                    var date = new Date(data.loan.addDate);
                    return date.Format("yyyy年MM月dd日");
                }
            },
            {
                label: "还款",
                align: "center",
                render: function (value, data) {
                    if (data.loan === undefined) {
                        return '';
                    }
                    var repayButton = '<button type="button" class="btn-default" data-icon="reply" onclick="repay(\'' + data.loan.loanId + '\',false);">还款</button>';
                    return repayButton;
                }
            },
            {
                label: "提前还款",
                align: "center",
                render: function (value, data) {
                    if (data.loan === undefined) {
                        return '';
                    }
                    var repayButton = '<button type="button" class="btn-default" data-icon="reply" onclick="repay(\'' + data.loan.loanId + '\',true);">提前还款</button>';
                    return repayButton;
                }
            }
        ];
        $("#loanReturningTable").datagrid({
            height: '100%',
            width: '100%',
            fullGrid : true,
            showToolbar: false,
            showTfoot : true,
            filterThead: false,
            dataUrl: '/admin/loan/loan/ajax/returning',
            local: "remote",
            inlineEditMult: false,
            delConfirm: true,
            columns: columns,
            paging: {pageSize: 20, pageIndex: 1},
            linenumberAll: true
        });

    });

    function repay(loanId, isAdvance) {
        if (!loanId) return;

        var openURL = "/admin/loan/repay/repay";

        BJUI.dialog({
            id: "repay" + loanId,
            url: openURL,
            data: {
                loanId: loanId,
                isAdvance: isAdvance,
                isInfo: false
            },
            title: loanId + "还款",
            refresh: true,
            width: 800,
            height: 800 * 0.618
        })
    }

</script>